package com.itHsuSE.demo8;

import java.sql.*;

/**
 * @author Hsu琛君珩
 * @ClassName:DBUtil
 * @date 2023-12-19
 * @apiNote
 * @Version: v1.0
 */

public class DBUtil {
    private static Connection connection;
    private static Statement statement;
    private static ResultSet resultSet;

    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/testGUI?useSSL=false";
            String user="root";
            String password="123456";
            connection= DriverManager.getConnection(url,user,password);
        }catch (Exception e){
            System.out.println(e);
        }finally {
            return connection;
        }
    }

    public static void close()throws SQLException{
        if(resultSet!=null)resultSet.close();
        if(statement!=null)statement.close();
        if(connection!=null)connection.close();
    }

}
